package top.hkyzf.study.leetcode.string;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-15 11:48
 */
public class 有效的字母异位词_242 {
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        int[] ints = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            ints[ch-'a']++;
        }
        for (int i = 0; i < t.length(); i++) {
            char ch = t.charAt(i);
            ints[ch-'a']--;
            if (ints[ch-'a'] < 0) {
                return false;
            }
        }
        return true;
    }

    @Test
    public void testIsAnagram () {
        String s = "ab";
        String t = "a";
        System.out.println(isAnagram(s, t));
    }
}
